from PyQt5.QtCore import pyqtSignal

class QRouter(object):
    # 信号构建器：每个参与路由的窗口类都必须继承该类。
    class RouteSignal(object):
        signal = pyqtSignal(type, tuple)

    def __init__(self, home, data) -> None:
        super(QRouter, self).__init__()
        self.handle(home, data)

    # 路由处理器
    def handle(self, clazz, data) -> None:
        clazz_instance = clazz(data)
        clazz_instance.show()
        clazz_instance.signal.connect(lambda to_clazz, data: (clazz_instance.close(), self.handle(to_clazz, data)))